#!/bin/bash

yum install -y yum-utils device-mapper-persistent-data lvm2 || exit 1
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
#   Loading mirror speeds from cached hostfile
#   Loaded plugins: branch, fastestmirror, langpacks
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            @docker-ce-stable
#   docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
#   Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]

yum install -y docker-ce 
mkdir /etc/docker

cat << EOF > /etc/docker/daemon.json
{
  "exec-opts":["native.cgroupdriver=systemd"], 
  "registry-mirrors":["https://fl7idj1l.mirror.aliyuncs.com"],
  "log-driver":"json-file",
  "log-opts": {
    "max-size":"100m"
  } 
}
EOF

systemctl daemon-reload
systemctl start docker && systemctl enable docker &> /dev/null || exit 3
systemctl status docker | grep active &> /dev/null && echo "Docker 已安装成功"
docker version